package com.spzx.report.aiUtils;

import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.model.output.Response;

/*
* 作用: 获取文本向量值
* 模型: text-embedding-v2
* 平台: 百炼平台
* */
public class SpzxEmbeddingTools {
    public static Embedding getEmbedding(String text) {
        //构造向量化嵌入模型
        EmbeddingModel embeddingModel = OpenAiEmbeddingModel.builder()
                .apiKey(SpzxAiConst.DASHSCOPE_API_KEY)
                .baseUrl(SpzxAiConst.DASHSCOPE_API_BASEURL)
                .modelName(SpzxAiConst.ALI_EMBEDDINGS_MODEL)
                .build();

        Response<Embedding> response = embeddingModel.embed(text);
        Embedding content = response.content();
        return content;
    }
}
